package com.airsystem.pos.bengkel.view;

import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.WindowConstants;

import com.airsystem.pos.bengkel.controller.LoginController;
import com.airsystem.pos.bengkel.util.TextUtil;

/**
 * @author Budi Oktaviyan <budi.oktaviyan@icloud.com>
 */
public class Login extends LoginController {

	public Login() {
		super();

		this.setIconImage(new ImageIcon(getClass().getResource("/images/login.png")).getImage());
		initComponents();
	}

	private void initComponents() {
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		setTitle("Login Aplikasi");
		setResizable(false);

		baseLayout.columnWidths = new int[] { 400, 0 };
		baseLayout.rowHeights = new int[] { 170, 30, 0 };
		baseLayout.columnWeights = new double[] { 0.0, Double.MIN_VALUE };
		baseLayout.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
		getContentPane().setLayout(baseLayout);

		panelLayout.columnWidths = new int[] { 50, 30, 200, 0 };
		panelLayout.rowHeights = new int[] { 35, 30, 20, 30, 0 };
		panelLayout.columnWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE };
		panelLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
		basePanel.setLayout(panelLayout);

		userLabel.setFont(new Font("Verdana", 0, 12));
		userLabel.setText("Username");

		passLabel.setFont(new Font("Verdana", 0, 12));
		passLabel.setText("Password");

		userField.setFont(new Font("Verdana", 0, 12));
		userField.setColumns(15);
		userField.setDocument(new TextUtil(15, TextUtil.ALPHANUMERIC));

		passField.setFont(new Font("Verdana", 0, 12));
		passField.setColumns(15);
		passField.setDocument(new TextUtil(30, TextUtil.PASSWORD));

		buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));

		loginButton.setIcon(new ImageIcon(getClass().getResource("/images/logon.png")));
		loginButton.setFont(new Font("Verdana", 1, 12));
		loginButton.setText("LOGIN");
		buttonPanel.add(loginButton);

		loginButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				loginButtonActionPerformed(evt);
			}
		});

		basePanel.add(userLabel, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 10), 0, 0));
		basePanel.add(passLabel, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 10), 0, 0));
		basePanel.add(userField, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 20, 0, 0), 0, 0));
		basePanel.add(passField, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 20, 0, 0), 0, 0));

		getContentPane().add(basePanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
		getContentPane().add(buttonPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));

		setSize(400, 250);
		setLocationRelativeTo(this);
	}

	private void loginButtonActionPerformed(ActionEvent evt) {
		login();
	}
}